class Solution {
public:
    int hIndex(vector<int>& citations)
    {
        int n = citations.size();
        ranges::sort(citations);
        for (int i = n; i >= 0; i--)
        {
            int it = lower_bound(citations.begin(), citations.end(), i) - citations.begin();
            if (n - it >= i) return i;
        }
        return 0;
    }
};